package com.ysqcould.web.controller.revita;


import com.ysqcould.common.annotation.Log;
import com.ysqcould.common.core.controller.BaseController;
import com.ysqcould.common.core.domain.AjaxResult;
import com.ysqcould.common.core.page.TableDataInfo;
import com.ysqcould.common.enums.BusinessType;
import com.ysqcould.common.utils.poi.ExcelUtil;
import com.ysqcould.revita.domain.GslTowns;
import com.ysqcould.revita.domain.HelpAssociation;
import com.ysqcould.revita.service.IGslTownsService;
import com.ysqcould.revita.service.IHelpAssociationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 乡村振兴内容Controller
 * 
 * @author ruoyi
 * @date 2022-06-30
 */
@RestController
@RequestMapping("/revita/association")
public class HelpAssociationController extends BaseController
{
    @Autowired
    private IHelpAssociationService helpAssociationService;

    @Resource
    private IGslTownsService gslTownsService;

    /**
     * 查询乡村振兴内容列表
     */
    @PreAuthorize("@ss.hasPermi('revita:association:list')")
    @GetMapping("/list")
    public TableDataInfo list(HelpAssociation helpAssociation)
    {
        startPage();
        List<HelpAssociation> list = helpAssociationService.selectHelpAssociationList(helpAssociation);
        return getDataTable(list);
    }

    /**
     * 导出乡村振兴内容列表
     */
    @PreAuthorize("@ss.hasPermi('revita:association:export')")
    @Log(title = "乡村振兴内容", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HelpAssociation helpAssociation)
    {
        List<HelpAssociation> list = helpAssociationService.selectHelpAssociationList(helpAssociation);
        ExcelUtil<HelpAssociation> util = new ExcelUtil<HelpAssociation>(HelpAssociation.class);
        util.exportExcel(response, list, "乡村振兴内容数据");
    }

    /**
     * 获取乡村振兴内容详细信息
     */
    @PreAuthorize("@ss.hasPermi('revita:association:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(helpAssociationService.selectHelpAssociationById(id));
    }

    /**
     * 获取乡村振兴内容详细信息
     */
    @PostMapping(value = "/{id}")
    public AjaxResult getTownList(@PathVariable("id") Long id)
    {
        final HelpAssociation association = helpAssociationService.selectHelpAssociationById(id);
        final List<GslTowns> gslTowns = gslTownsService.selectGslTown(association.getCityName());
        return AjaxResult.success(gslTowns);
    }

    /**
     * 新增乡村振兴内容
     */
    @PreAuthorize("@ss.hasPermi('revita:association:add')")
    @Log(title = "乡村振兴内容", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HelpAssociation helpAssociation)
    {
        helpAssociation.setAsId(getUserId());
        return toAjax(helpAssociationService.insertHelpAssociation(helpAssociation));
    }

    /**
     * 修改乡村振兴内容
     */
    @PreAuthorize("@ss.hasPermi('revita:association:edit')")
    @Log(title = "乡村振兴内容", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HelpAssociation helpAssociation)
    {
        return toAjax(helpAssociationService.updateHelpAssociation(helpAssociation));
    }

    /**
     * 删除乡村振兴内容
     */
    @PreAuthorize("@ss.hasPermi('revita:association:remove')")
    @Log(title = "乡村振兴内容", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(helpAssociationService.deleteHelpAssociationByIds(ids));
    }
}
